/**
 * @file common_inner.h
 *
 * Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifndef ACL_COMMON_INNER_API_H_
#define ACL_COMMON_INNER_API_H_

#include <map>
#include "acl/acl_base.h"
#include "acl/acl_rt.h"
#include "runtime/mem_base.h"
#include "log_inner.h"

namespace acl {
    constexpr size_t SOC_VERSION_LEN = 128U;

    ACL_FUNC_VISIBILITY const std::string &GetSocVersion();

    ACL_FUNC_VISIBILITY aclError InitSocVersion();

    using GeFinalizeCallback = aclError (*)();

    ACL_FUNC_VISIBILITY void SetGeFinalizeCallback(const GeFinalizeCallback func);

    ACL_FUNC_VISIBILITY aclError aclMallocMemInner(void **devPtr,
                                                   const size_t size,
                                                   bool isPadding,
                                                   const aclrtMemMallocPolicy policy,
                                                   const uint16_t moduleId);

    ACL_FUNC_VISIBILITY aclError aclrtMallocInnerWithCfg(void **devPtr,
                                                         const size_t size,
                                                         aclrtMemMallocPolicy policy,
                                                         rtMallocAdvise advise,
                                                         aclrtMallocConfig *cfg);

    bool GetAclInitFlag();

    uint64_t GetAclInitRefCount();

    ACL_FUNC_VISIBILITY void SetThreadCompileOpts(const std::map<std::string, std::string> &options);

    void SetCastHasTruncateAttr(const bool hasTruncate);

    void resetAclJsonHash();

    bool GetIfCastHasTruncateAttr();

    void SetGlobalCompileFlag(const int32_t flag);

    int32_t GetGlobalCompileFlag();

    void SetGlobalJitCompileFlag(const int32_t flag);

    int32_t GetGlobalJitCompileFlag();

    void aclGetMsgCallback(const char_t *msg, uint32_t len);

    aclError UpdatePlatformInfoWithDevice(int32_t deviceId);

    aclError GetPlatformInfoWithKey(const std::string &key, int64_t *value);

    int32_t UpdateOpSystemRunCfg(void *cfgAddr, uint32_t cfgLen);

    aclError HandleDefaultDevice(const char_t *const configPath);
    void HandleReleaseSourceByStream(aclrtStream stream, bool isCreate);
    void HandleReleaseSourceByDevice(uint32_t devId, bool isReset);

    ACL_FUNC_VISIBILITY aclError GetAlignedAndPaddingSize(const size_t size, const bool isPadding, size_t &alignedSize);
}

#endif // ACL_COMMON_INNER_API_H_
